/*
@title: IT COULD BE
@author: TromboneBoi9
@tags: ['music', 'retro', 'adventure']
@addedOn: 2025-02-18
@description: An artistic game inspired by Philip Glass's opera "Einstein on the Beach". Features unique music arrangements and explores themes of politics, philosophy, and autism through analog horror aesthetics.

I have a website!!!
<< https://tilde.town/~/tromboneboi9/ >>
*/

/*
Creative insights:

This "game" is largely inspired by
- Philip Glass's opera "Einstein on the Beach"
- thoughts I've had regarding politics and philosophy
- my own experiences with high-functioning autism
- some analog horror aesthetics

The music is an arrangement of Act IV, Scene I of Glass's
opera, titled "Building".
*/

const player = "p";
const face = "f";
const bubble = "b";
const guy = "g";
const wall = "w";
const deus = "d";
const corpse = "c";
const angryface = "a";

const glasses = [
  tune``,
  tune`
  100: D#2-200 + D#6-200,
  100: A#2-100 + G#5-100,
  100: C3-100 + F5-100,
  100: D#3-100 + D#5-100,
  100: C3-100 + F5-100,
  100: A#2-100 + G#5-100
  `,
  tune`
  100: D#2-200 + D#6-200,
  100: A#2-100 + G#5-100,
  100: D#2-200 + D#6-200,
  100: A#2-100 + G#5-100,
  100: C3-100 + F5-100,
  100: D#3-100 + D#5-100,
  100: C3-100 + F5-100,
  100: A#2-100 + G#5-100
  `,
  tune`
  100: D#2-200 + D#6-200 + A#3^2000,
  100: A#2-100 + G#5-100,
  100: D#2-200 + D#6-200,
  100: A#2-100 + G#5-100,
  100: D#2-200 + D#6-200,
  100: A#2-100 + G#5-100,
  100: C3-100 + F5-100,
  100: D#3-100 + D#5-100,
  100: C3-100 + F5-100,
  100: A#2-100 + G#5-100
  `,
  tune`
  100: D#2-200 + D#6-200 + D#3^1600,
  100: A#2-100 + G#5-100,
  100: D#2-200 + D#6-200,
  100: A#2-100 + G#5-100,
  100: C3-100 + F5-100,
  100: D#3-100 + D#5-100,
  100: C3-100 + F5-100,
  100: A#2-100 + G#5-100
  `,
  tune`
  100: D#2-200 + D#6-200 + D#2^1200 + C#3^1200,
  100: A#2-100 + G#5-100,
  100: C3-100 + F5-100,
  100: D#3-100 + D#5-100,
  100: C3-100 + F5-100,
  100: A#2-100 + G#5-100
  `,
  tune`
  100: D#2-200 + D#6-200 + C#2^1600 + G#3^1600,
  100: A#2-100 + G#5-100,
  100: D#2-200 + D#6-200,
  100: A#2-100 + G#5-100,
  100: C3-100 + F5-100,
  100: D#3-100 + D#5-100,
  100: C3-100 + F5-100,
  100: A#2-100 + G#5-100
  `,
  tune`
  100: D#2-200 + D#6-200 + C2^2000 + A#3^2000,
  100: A#2-100 + G#5-100,
  100: D#2-200 + D#6-200,
  100: A#2-100 + G#5-100,
  100: D#2-200 + D#6-200,
  100: A#2-100 + G#5-100,
  100: C3-100 + F5-100,
  100: D#3-100 + D#5-100,
  100: C3-100 + F5-100,
  100: A#2-100 + G#5-100
  `,
  tune`
  100: D#2-200 + D#6-200 + D#2^2200 + D#4^2200,
  100: A#2-100 + G#5-100,
  100: D#2-200 + D#6-200,
  100: A#2-100 + G#5-100,
  100: D#2-200 + D#6-200,
  100: A#2-100 + G#5-100,
  100: C3-100 + F5-100,
  100: D#3-100 + D#5-100,
  100: C3-100 + F5-100,
  100: D#3-100 + D#5-100,
  100: C3-100 + F5-100,
  100: A#2-100 + G#5-100
  `,
  tune`
  100: D#2-200 + D#6-200 + E2^2400 + F#4^2400,
  100: A#2-100 + G#5-100,
  100: D#2-200 + D#6-200,
  100: A#2-100 + G#5-100,
  100: D#2-200 + D#6-200,
  100: A#2-100 + G#5-100,
  100: C3-100 + F5-100,
  100: D#3-100 + D#5-100,
  100: C3-100 + F5-100,
  100: D#3-100 + D#5-100,
  100: C3-100 + F5-100,
  100: D#3-100 + D#5-100,
  100: C3-100 + F5-100,
  100: A#2-100 + G#5-100
  `,
  tune`
  100: D#2-200 + D#6-200 + C2^2400 + G4^2400,
  100: A#2-100 + G#5-100,
  100: D#2-200 + D#6-200,
  100: A#2-100 + G#5-100,
  100: D#2-200 + D#6-200,
  100: A#2-100 + G#5-100,
  100: C3-100 + F5-100,
  100: D#3-100 + D#5-100,
  100: C3-100 + F5-100,
  100: D#3-100 + D#5-100,
  100: C3-100 + F5-100,
  100: D#3-100 + D#5-100,
  100: C3-100 + F5-100,
  100: A#2-100 + G#5-100
  `,
  tune`
  100: D#2-200 + D#6-200 + F2^1200 + F4^1200,
  100: A#2-100 + G#5-100,
  100: D#2-200 + D#6-200,
  100: A#2-100 + G#5-100,
  100: D#2-200 + D#6-200,
  100: A#2-100 + G#5-100,
  100: C3-100 + F5-100,
  100: D#3-100 + D#5-100 + D#2^1200 + G#4^1200,
  100: C3-100 + F5-100,
  100: D#3-100 + D#5-100,
  100: C3-100 + F5-100,
  100: D#3-100 + D#5-100,
  100: C3-100 + F5-100,
  100: A#2-100 + G#5-100
  `,
  tune`
  100: D#2-200 + D#6-200 + D#2^2400 + A#4^2400,
  100: A#2-100 + G#5-100,
  100: D#2-200 + D#6-200,
  100: A#2-100 + G#5-100,
  100: D#2-200 + D#6-200,
  100: A#2-100 + G#5-100,
  100: C3-100 + F5-100,
  100: D#3-100 + D#5-100,
  100: C3-100 + F5-100,
  100: D#3-100 + D#5-100,
  100: C3-100 + F5-100,
  100: D#3-100 + D#5-100,
  100: C3-100 + F5-100,
  100: A#2-100 + G#5-100
  `,
  tune`
  100: D#2-200 + D#6-200 + D#2^2400 + D#5^200,
  100: A#2-100 + G#5-100 + G#4^100,
  100: D#2-200 + D#6-200 + D#5^200,
  100: A#2-100 + G#5-100 + G#4^100,
  100: D#2-200 + D#6-200 + D#5^200,
  100: A#2-100 + G#5-100 + G#4^100,
  100: C3-100 + F5-100 + F4^100,
  100: D#3-100 + D#5-100 + D#4^100,
  100: C3-100 + F5-100 + F4^100,
  100: D#3-100 + D#5-100 + D#4^100,
  100: C3-100 + F5-100 + F4^100,
  100: D#3-100 + D#5-100 + D#4^100,
  100: C3-100 + F5-100 + F4^100,
  100: A#2-100 + G#5-100 + G#4^100
  `,
  tune`
  100: D#2-200 + D#6-200 + D#2^200 + D#5^200,
  100: A#2-100 + G#5-100 + A#2^100 + G#4^100,
  100: D#2-200 + D#6-200 + D#2^200 + D#5^200,
  100: A#2-100 + G#5-100 + A#2^100 + G#4^100,
  100: D#2-200 + D#6-200 + D#2^100 + D#5^200,
  100: A#2-100 + G#5-100 + A#2^100 + G#4^100,
  100: C3-100 + F5-100 + C3^100 + F4^100,
  100: D#3-100 + D#5-100 + D#3^100 + D#4^100,
  100: C3-100 + F5-100 + C3^100 + F4^100,
  100: D#3-100 + D#5-100 + D#3^100 + D#4^100,
  100: C3-100 + F5-100 + C3^100 + F4^100,
  100: D#3-100 + D#5-100 + D#3^100 + D#4^100,
  100: C3-100 + F5-100 + C3^100 + F4^100,
  100: A#2-100 + G#5-100 + A#2^100 + G#4^100
  `,
  tune`
  100: D#2-200 + D#6-200 + D#2^200 + D#5^200,
  100: A#2-100 + G#5-100 + A#2^100 + G#4^100,
  100: C3-100 + F5-100 + C3^100 + F4^100,
  100: D#3-100 + D#5-100 + D#3^100 + D#4^100,
  100: C3-100 + F5-100 + C3^100 + F4^100,
  100: A#2-100 + G#5-100 + A#2^100 + G#4^100
  `,
  tune``
]

const bitmaps = [
  bitmap`
..000000000000..
.00000000000000.
0002222200000000
0022222222222000
0022222222222200
0020000220000200
0022222220222200
0022222220222200
0022222220222200
0022222000222200
0022222222222200
0022220000222200
0002222222222000
.0.0222222220.0.
...0000220000...
...0000000000...`,
  bitmap`
.............000
............0...
............0...
..........00....
.........0......
.........0......
..........00....
......00....0...
.....0..0...0...
.....0..0...0...
......00....0...
............0...
....0.......0...
...0.0......0...
....0........000
................`,
  bitmap`
................
......0000......
.....022220.....
.....022220.....
......0000......
................
....00000000....
...0.022220.0...
...0.022220.0...
...0.022220.0...
...0.022220.0...
...0.022220.0...
.....000000.....
.....0....0.....
.....0....0.....
.....0....0.....`,
  bitmap`
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000`,
  bitmap`
....66666666....
...6222222226...
..622222222226..
.62222222222226.
6220000220000226
6222222220222226
6222222220222226
6222222220222226
6222222220222226
6222222000222226
6222222222222226
6222022222202226
.62220000002226.
..622222222226..
...6222222226...
....66666666....`,
  bitmap`
................
................
................
................
................
................
..........00000.
.........0......
0000000000..00..
...0222220.0220.
...0222220.0220.
...0222220.0220.
...0222220.0220.
0000000000..00..
.........0......
..........00000.`,
  bitmap`
..000000000000..
.00000000000000.
0002222200000000
0022222222222000
0022220220222200
0020002222000200
0027722220222200
0022722220222200
0022722220222200
0022722000222200
0022722222222200
0022720000222200
0002722222222000
.0.0722222220.0.
...0000220000...
...0000000000...`
]

const texts = [
  "IT",
  "IT COULD",
  "IT COULD BE",
  "(cont)",
  "IDEAS",
  "IDEAS ARE",
  "IDEAS ARE BORN",
  "(cont)",
  "WHEN",
  "WHEN PUT",
  "WHEN PUT IN",
  "(cont)",
  "THE",
  "THE REAL",
  "THE REAL WORLD",
  "(cont)",
  "BUT",
  "BUT ALL",
  "BUT ALL THINGS",
  "(cont)",
  "RETURN",
  "RETURN TO",
  "RETURN TO DUST",
  "(cont)",
  "IT",
  "IT MEANS",
  "IT MEANS THAT",
  "(cont)",
  "IDEAS",
  "IDEAS LEECH",
  "IDEAS LEECH ON",
  "(cont)",
  "PEOPLE",
  "PEOPLE LISTENING",
  "(cont)",
  "PEOPLE",
  "PEOPLE THINKING",
  "(cont)",
  "MOST",
  "MOST IMPORTANTLY",
  "(cont)",
  "PEOPLE",
  "PEOPLE ACTING",
  "(cont)",
  "THE",
  "THE LONE",
  "THE LONE THINKER",
  "(cont)",
  "IS",
  "IS NO",
  "IS NO THINKER",
  "(cont)",
  "AT",
  "AT ALL.",
  "(cont)",
  ","
]

addText("WASD", { y: 0, color: color`3` })

const turning = [
  bitmap`
................
.......00.......
.......00.......
.......00.......
.......00.......
.......00.......
.......00.......
.......00.......
.......00.......
................
................
................
................
................
................
................`,
  bitmap`
................
................
............00..
...........000..
..........000...
.........000....
........000.....
.......000......
.......00.......
................
................
................
................
................
................
................`,
  bitmap`
................
................
................
................
................
................
................
.......00000000.
.......00000000.
................
................
................
................
................
................
................`,
  bitmap`
................
................
................
................
................
................
................
.......00.......
.......000......
........000.....
.........000....
..........000...
...........000..
............00..
................
................`,
  bitmap`
................
................
................
................
................
................
................
.......00.......
.......00.......
.......00.......
.......00.......
.......00.......
.......00.......
.......00.......
.......00.......
................`,
  bitmap`
................
................
................
................
................
................
................
.......00.......
......000.......
.....000........
....000.........
...000..........
..000...........
..00............
................
................`,
  bitmap`
................
................
................
................
................
................
................
.00000000.......
.00000000.......
................
................
................
................
................
................
................`,
  bitmap`
................
................
..00............
..000...........
...000..........
....000.........
.....000........
......000.......
.......00.......
................
................
................
................
................
................
................`,
]

var currentBitmap = 0;
 
function setSprites() {
  setLegend(
    [player, turning[currentBitmap]],
    [face, bitmaps[0]],
    [bubble, bitmaps[1]],
    [guy, bitmaps[2]],
    [wall, bitmaps[3]],
    [deus, bitmaps[4]],
    [corpse, bitmaps[5]],
    [angryface, bitmaps[6]]
  )
}
setSprites()

const a = setInterval(() => {
  currentBitmap = (currentBitmap + 1) % turning.length;
  setSprites();
}, 1000)

setSolids([player, face, bubble, wall, angryface])

let level = 0
const levels = [
  map`
...
bp.
f..`,
  map`
.g...
.....
..p..
.....
...g.`,
  map`
...g...
.g.....
....g..
...p...
.......
..g...g
g......`,
  map`
.g.......
...g..g..
.........
........g
.g..pg...
.........
.........
g.g....g.
.........`,
  map`
.........
....ww...
...w..w..
..w....w.
..w....w.
..w....w.
..wggp.w.
..wwwwww.
.........`,
  map`
.........
.www.g...
.........
.w..w..w.
.g..g..g.
....p....
.w..w..w.
.g..g..g.
.........`,
  map`
....g....
..g.w.g..
..w.w.w..
.........
....p....
g.......g
.........
.g.....g.
....g....`,
  map`
.....
.....
.gpg.
.....
.....`,
  map`
gg.gg
gg.gg
ggpgg
gg.gg
gg.gg`,
  map`
c..cg
.g...
..pgc
g.c..
.c..g`,
  map`
.....
..gp.
.ccc.
ccccc
ccccc`,
  map`
.......
...gp..
..ccc..
.ccccc.
ccccccc
ccccccc
ccccccc`,
  map`
.........
....gp...
...ccc...
..ccccc..
.ccccccc.
ccccccccc
ccccccccc
ccccccccc
ccccccccc`,
  map`
............
............
..d...wwww..
.....w....w.
....w......w
....w......w
....w..p...w
....w......w
.....w....w.
......wwww..
............
............`,
  map`
............
.......ww...
..d......w..
............
............
...w........
...w...p...w
...........w
............
.....w......
......wwww..
............`,
  map`
...
bp.
a..`
]

setMap(levels[level])

setPushables({
  [player]: []
})

function endRoutine() {
  playback.end()
  setBackground(wall)
  setMap(map`
...
...
...`)
  addText("IT COULD BE",{y:1,color:color`2`})
  addText("TromboneBoi9",{y:3,color:color`2`})
  addText("Thank you for",{y:5,color:color`2`})
  addText("\"playing\"",{y:7,color:color`2`})
  addText("My website:",{y:9,color:color`2`})
  addText("https\:\/\/tilde.town",{y:11,color:color`3`})
  addText("\/(TILDE)",{y:13,color:color`3`})
  addText("\/tromboneboi9",{y:15,color:color`3`})
}

onInput("w", () => { getFirst(player).y -= 1 })
onInput("a", () => { getFirst(player).x -= 1 })
onInput("s", () => { getFirst(player).y += 1 })
onInput("d", () => { getFirst(player).x += 1 })

let playback = playTune(``, Infinity)
let textStage = -1;
afterInput(() => {
  clearText();
  textStage += 1;
  if (texts[textStage] == "(cont)") {
    level += 1;
    playback.end()
    playback = playTune(glasses[level], Infinity)
    setMap(levels[level])
  } else if (texts[textStage] == "(end)") {
    endRoutine()
  } else {
    addText(texts[textStage], { y: 0, color: color`0` });
  }
})